<template>
  <div class="login-container">
    <el-alert v-show="false" title="后台管理" type="success" :closable="false" style="position: fixed"></el-alert>
    <el-row>
      <el-col :xs="24" :sm="24" :md="12" :lg="14" :xl="14">
        <div style="color: transparent">左侧区域占位符</div>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="10" :xl="10">
        <el-form status-icon class="login-form">
          <div class="form-header">
            <div class="title">hello !</div>
            <div class="title-tips">
              欢迎来到后台管理！
            </div>
          </div>
          <el-form-item prop="username">
            <el-input v-model="userInfo.username" :prefix-icon="User" autocomplete="off" placeholder="请输入用户名" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="userInfo.password" type="password" :prefix-icon="Lock" autocomplete="off" placeholder="请输入密码" />
          </el-form-item>
          <el-form-item prop="captchaCode">
            <el-row>
              <el-col :span="15">
                <el-input v-model="userInfo.captchaCode" autocomplete="off" placeholder="请输入验证码" />
              </el-col>
              <el-col :span="8" :offset="1">
                <el-image @click="getCaptchaCode" :src="userInfoStore.captcha.image" fit="contain" style="height: 100%; background: white" class="pointer" />
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item>
            <el-button @click="login" class="login-btn" type="primary" size="large">
              登陆
            </el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">

import { User, Lock } from '@element-plus/icons-vue'
import { onMounted, reactive } from 'vue';
import { useRouter } from 'vue-router';
import { useUserInfoStore } from '@/store/modules/model/userInfoModel';
import { ElMessage } from 'element-plus';

let userInfo = reactive({
  username:"admin",
  password:"123456",
  captchaKey:"",
  captchaCode:""
})
let router = useRouter();

let userInfoStore = useUserInfoStore()
//在页面初始化时获取验证码
onMounted(() => {
  getCaptchaCode()
})
//获取验证码
let getCaptchaCode = () => {
  userInfoStore.getCaptchaCode()
}
//登陆
let login = async () => {
  userInfo.captchaKey = userInfoStore.captcha.key
  await userInfoStore.checkLogin(userInfo)
  ElMessage.success("登陆成功")
  router.push("/")
}
</script>

<style scoped lang="scss">
@import './index';
</style>
